﻿/*
=======================================================
    StandStatusDetail【状态标准明细】
=======================================================
*/

namespace Services
{
    public interface IStandStatusDetailMapping : IMapping<StandStatusDetail, StandStatusDetailModel, StandStatusDetailFilterModel>
    { }

    public class StandStatusDetailMapping : AutoStandStatusDetailMapping, IStandStatusDetailMapping
    {
        public StandStatusDetailMapping(ICurrentUser currentUser)
            : base(currentUser)
        { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override StandStatusDetailModel Entity2Model(StandStatusDetail entity)
        {
            if (entity == null)
            {
                return null;
            }

            StandStatusDetailModel model = base.Entity2Model(entity);


            /***************************************** 下面处理自定义转换 *****************************************/

            model.Hoister_Name = entity.Hoister_Name;
            model.HoisterUsage_Name = entity.HoisterUsage_Name;
            model.HoisterUsage_IsDelete = entity.HoisterUsage_IsDelete;
            model.WireropeType_Name = entity.WireropeType_Name;
            model.WireropeType_IsDelete = entity.WireropeType_IsDelete;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override StandStatusDetail Model2Entity(StandStatusDetailModel model)
        {
            StandStatusDetail entity = base.Model2Entity(model);


            /***************************************** 下面处理自定义转换 *****************************************/



            return entity;
        }
        #endregion

        #region 读数据(集合)
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entities">Entity对象</param>
        /// <returns></returns>
        public override List<StandStatusDetailModel> Entity2Model(IEnumerable<StandStatusDetail> entities)
        {
            return entities.Select(x => Entity2Model(x)).ToList();
        }
        #endregion

        #region 写数据(集合)
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="models">ViewModel对象</param>
        /// <returns></returns>
        public override List<StandStatusDetail> Model2Entity(IEnumerable<StandStatusDetailModel> models)
        {
            return models.Select(x => Model2Entity(x)).ToList();
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<StandStatusDetail> FilterModel2Where(StandStatusDetailFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //SearchInput
            if (!string.IsNullOrEmpty(filterModel._SearchInput))
            { }

            ////绿灯
            //if (filterModel._GreenLight.HasValue)
            //{
            //    where = where.And(x => x.GreenLight == filterModel._GreenLight.Value);
            //}

            ////蓝灯
            //if (filterModel._BlueLight.HasValue)
            //{
            //    where = where.And(x => x.BlueLight == filterModel._BlueLight.Value);
            //}

            ////黄灯
            //if (filterModel._YellowLight.HasValue)
            //{
            //    where = where.And(x => x.YellowLight == filterModel._YellowLight.Value);
            //}

            ////橙灯
            //if (filterModel._OrangeLight.HasValue)
            //{
            //    where = where.And(x => x.OrangeLight == filterModel._OrangeLight.Value);
            //}


            return where;
        }
        #endregion
    }
}
